package com.neuedu.shop.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neuedu.shop.mapper.AdminMapper;
import com.neuedu.shop.pojo.Admin;
import com.neuedu.shop.service.AdminService;
import com.neuedu.shop.util.Util;

/**
 * @author ZhangHongRui
 *
 *         2019年12月26日
 */
@Service
@Transactional
public class AdminServiceImpl implements AdminService {

	/**
	 * 持有持久层接口的对象
	 */
	@Autowired // 自动注入 dependency injection
	private AdminMapper mapper;

	/**
	 * 在业务层中调用持久层中的结果
	 */

	@Override
	public List<Admin> findAll() {
		return mapper.findAll();
	}

	@Override
	public Admin login(String name, String pwd) {
		Admin admin = mapper.findByName(name);
		if (admin != null && admin.getPassword().equals(Util.getMD5(pwd))) {
			return admin;
		}
		return null;
	}

}
